<?php
/**
 * created by zzy
 * date: 2018/1/16 10:48
 */
namespace App\Eloquent\Ygt;

class Seller extends DbEloquent{

    protected $table    = 'ygt_seller';

    public static $tableFieldList   = [
        ['name'=>'id','title'=>'','value'=>0,'is_must'=>0],
        ['name'=>'title','title'=>'供应商名称','value'=>'','is_must'=>1],
        ['name'=>'mobile','title'=>'供应商电话','value'=>'','is_must'=>1],
    ];
    //注册供应商,若不存在则注册,若存在则取存在的id
    //返回值 status==0失败,status==1不存在注册,status==1存在取存在的id
    public static function registerSeller($mobile,$title)
    {
        $where          = ['mobile'=>$mobile];
        $info           = self::getInfo($where);
        if(!$info){
            //注册账号
            $data           = [
                'mobile'=>$mobile,
                'title'=>$title,
            ];
            $insertId       = self::insertOneData( $data, 'id' );
            if(!$insertId){
                $result     = [ 'status'=>0,'message'=>'关联账号注册失败','id'=>0 ];
                return $result;
            }else{
                $result     = [ 'status'=>1,'message'=>'','id'=>$insertId ];
                return $result;
            }
        }else{
            $result         = [ 'status'=>2,'message'=>'','id'=>$info->id ];
            return $result;
        }
    }

}
